{php include wl_template('common/header');}
<style>
    red{color: #ed5565;}
</style>
<ul class="nav nav-tabs">
    <li><a href="{php echo web_url('luckydraw/luckygoods/goodsIndex')}">奖品列表</a></li>
    <li class="active"><a href="javascript:;">编辑奖品</a></li>
</ul>
<div class="app-content">
    <div class="app-form">
        <div class="panel panel-default">
            <form class="form-horizontal form-validate" method="post">
                <div class="form-group-title">奖品类型</div>
                <!-- 奖品类型 -->
                <div class="form-group">
                    <label class="col-sm-2 control-label">奖品类型</label>
                    <div class="col-sm-9">
                        <label class="radio-inline">
                            <input type="radio" name="data[type]" value="1" {if $info['type'] == 1}checked="checked"{/if}> 现金红包
                        </label>
                        {if p('redpack') && j('redpack')}
                            <label class="radio-inline">
                                <input type="radio" name="data[type]" value="2" {if $info['type'] == 2}checked="checked"{/if}> 线上红包
                            </label>
                        {/if}
                        <label class="radio-inline">
                            <input type="radio" name="data[type]" value="3" {if $info['type'] == 3}checked="checked"{/if}> 积分
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="data[type]" value="4" {if $info['type'] == 4}checked="checked"{/if}> 激活码
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="data[type]" value="5" {if $info['type'] == 5}checked="checked"{/if}> 商品
                        </label>
                        <div class="help-block">
                            <span class="type-class type-red {if $info['type'] != 1}hide{/if}">中奖后将获得对应的<red>现金</red>奖励；请填写1-200之间的数据，否则红包会发送失败！</span>
                            <span class="type-class type-onlineRed {if $info['type'] != 2}hide{/if}">中奖后将获得一个对应的线上红包</span>
                            <span class="type-class type-integral {if $info['type'] != 3}hide{/if}">中奖后将获得对应的积分奖励</span>
                            <span class="type-class type-code {if $info['type'] != 4}hide{/if}">中奖后将获得对应序列的一个激活码</span>
                            <span class="type-class type-goods {if $info['type'] != 5}hide{/if}">中奖后将<red>免费</red>获得对应的商品,多规格商品不能作为奖品。</span>
                        </div>
                    </div>
                </div>
                <!-- 奖品类型为现金红包时 扩展内容 -->
                <div class="type-class type-red {if $info['type'] != 1}hide{/if}">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">领取方式</label>
                        <div class="col-sm-9">
                            <label class="radio-inline">
                                <input type="radio" name="data[get_type]" value="1" {if $info['get_type'] == 1}checked="checked"{/if}> 发送现金红包
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="data[get_type]" value="2" {if $info['get_type'] == 2}checked="checked"{/if}> 增加到余额
                            </label>
                            <div class="help-block">注意：选择发送现金红包时；请保证微信商户中余额充足！</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">红包金额</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="number" id="redPackageMoney" name="data[prize_number]" value="{$info['prize_number']}"/>
                        </div>
                    </div>
                </div>
                <!-- 奖品类型为线上红包时 扩展内容 -->
                <div class="type-class type-onlineRed  {if $info['type'] != 2}hide{/if}">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">选择红包</label>
                        <div class="col-sm-9">
                            {php echo tpl_select_redPack($info['red_pack_name'],$info['red_pack_id']);}
                        </div>
                    </div>
                </div>
                <!-- 奖品类型为积分时 扩展内容 -->
                <div class="type-class type-integral  {if $info['type'] != 3}hide{/if}">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">奖励积分</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="number" name="data[prize_number]" value="{$info['prize_number']}"/>
                        </div>
                    </div>
                </div>
                <!-- 奖品类型为激活码时 扩展内容 -->
                <div class="type-class type-code  {if $info['type'] != 4}hide{/if}">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">激活码(组)</label>
                        <div class="col-sm-9">
                            <select name="data[code_keyword]" class="form-control">
                                <option value="" selected>请选择一个激活码序列</option>
                                {loop $codeList $vo}
                                    <option value="{$vo['remark']}" {if $info['code_keyword'] == $vo['remark']}selected{/if}>{$vo['remark']}（{$vo['total']}份）</option>
                                {/loop}
                            </select>
                        </div>
                    </div>
                </div>
                <!-- 奖品类型为商品时 扩展内容 -->
                <div class="type-class type-goods  {if $info['type'] != 5}hide{/if}">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">选择商品</label>
                        <div class="col-sm-9 selectGoodsParams" params='{"is_optionstatus":1}'>
                            {php echo tpl_select_goods($info);}
                        </div>
                    </div>
                </div>
                <!-- 公共设置内容 -->
                <div class="form-group-title">基本设置</div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">奖品状态</label>
                    <div class="col-sm-9">
                        <label class="radio-inline">
                            <input type="radio" name="data[status]" value="1" {if $info['status'] == 1}checked="checked"{/if}> 上架
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="data[status]" value="2" {if $info['status'] != 1}checked="checked"{/if}> 下架
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">奖品名称</label>
                    <div class="col-sm-9">
                        <input class="form-control" type="text" required name="data[title]" value="{$info['title']}" maxlength="25"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">奖品logo</label>
                    <div class="col-sm-9">
                        {php echo attachment_select('data[image]', $info['image']);}
                    </div>
                </div>
                <!-- 提交按钮 -->
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-9">
                        <input type="hidden" name="token" value="{$_W['token']}" />
                        <input type="hidden" name="id" value="{$info['id']}" />
                        <input type="submit" name="submit" value="提交" class="btn btn-primary col-sm-1 min-width" />
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    /**
     * 点击更换类型
     */
    $("[name='data[type]']").on('click',function () {
        //隐藏所有内容
        $(".type-class").addClass('hide');
        //清空所有已填写内容
        $("[name='data[get_type]']:eq(0)").click();
        $("[name='data[prize_number]']").val(0.00);
        $("[name='data[red_pack_name]']").val('');
        $("[name='data[red_pack_id]']").val('');
        $("[name='data[code_keyword]']").val('');
        $("[name='data[goods_name]']").val('');
        $("[name='data[goods_id]']").val('');
        $("[name='data[goods_plugin]']").val('');
        $("[name='data[sid]']").val('');
        //根据type显示内容
        let type = parseInt($(this).val());
        switch (type) {
            case 1:$(".type-red").removeClass('hide');break;//现金红包
            case 2:$(".type-onlineRed").removeClass('hide');break;//线上红包
            case 3:$(".type-integral").removeClass('hide');break;//积分奖励
            case 4:$(".type-code").removeClass('hide');break;//激活码
            case 5:$(".type-goods").removeClass('hide');break;//商品
        }
    });
    /**
     * 信息同步
     */
    $("[name='data[prize_number]']").on('change',function () {
        let val  = $(this).val();
        $("[name='data[prize_number]']").val(val);
    });
    /**
     * 修改现金红包最小值
     */
    $("[name='data[get_type]']").on('change',function () {
        let val = $(this).val();
        if(val == 1) $("#redPackageMoney").attr('min',0.3);
        else $("#redPackageMoney").attr('min',0.01);
    });
</script>
{php include wl_template('common/footer');}
